#!/bin/bash

set -e

base_dir=$(cd `dirname $0`; pwd)
src_dir=${base_dir}/..

if [[ -z ${EMSDK} ]]; then
    source ${src_dir}/emsdk/emsdk_env.sh
fi

build_folder=${src_dir}/wasm-build
boost_dir=${EMSDK}/upstream/emscripten/system/include
pushd ${src_dir}

# cmake
cmake -Bwasm-build -DBoost_INCLUDE_DIR=${boost_dir} -DTW_COMPILE_WASM=ON -DCMAKE_TOOLCHAIN_FILE=${EMSDK}/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake

# make
make -j8 -Cwasm-build

popd
